using System;
using System.Collections.Generic;
using System.Text;

namespace SqlToolkit.Oracle.Schema
{
    public abstract class SqlBase : SqlToolkit.ISqlDataObject
    {
        protected SqlToolkit.Oracle.OracleDB _conn = null;

        internal string FriendlyName(string name)
        {
            StringBuilder ret = new StringBuilder();

            string[] parts = name.Split('_');

            for(int i = 0; i < parts.Length; i++)
            {
                string s = parts[i].ToLower();
                if (s != string.Empty)
                {
                    s = s[0].ToString().ToUpper() + s.Substring(1);
                    ret.Append(s);
                }
            }

            return ret.ToString();
        }

        internal string HeaderName(string name)
        {
            StringBuilder ret = new StringBuilder();

            string[] parts = name.Split('_');

            for (int i = 0; i < parts.Length; i++)
            {
                string s = parts[i].ToLower();
                s = s[0].ToString().ToUpper() + s.Substring(1);
                ret.Append(s);
                if (i < (parts.Length - 1))
                {
                    ret.Append(" ");
                }
            }

            return ret.ToString();
        }

        protected string _user = "";
        public string GetUser
        {
            get
            {
                if (null != _conn && _user == "")
                {
                    _user = _conn.DbAccessor.ExecuteSqlText.ExecuteScalar("SELECT DISTINCT ALL_TABLES.OWNER FROM ALL_TABLES WHERE ALL_TABLES.OWNER <> 'SYS' AND ALL_TABLES.OWNER <> 'SYSTEM' AND ALL_TABLES.OWNER <> 'WMSYS'").ToString();
                }
                return _user;
            }
        }

        public SqlToolkit.Oracle.OracleDB GetConnectionClone()
        {
            return (SqlToolkit.Oracle.OracleDB)_conn.Clone();
        }
    }
}
